package main

import (
	"ddy/go_study/version"
	"fmt"
)

var global_val string = "Gloabal Variable."
var (
	G1 = 123
	g2 = 456
)

func main() {
	fmt.Println("你好")

	//变量定义
	var v1 string = "Hello!"
	var v2 int = 65535
	v3 := 123
	fmt.Printf("%#v %#v %#v %#v\n", v1, v2, v3, global_val)
	fmt.Printf("%#v %#v\n", G1, g2)
	fmt.Println("version:", version.Version)
	// fmt.Println("name:", version.name)

	//输入输出
	var in_a int
	var in_b string
	fmt.Print("输入数字：")
	fmt.Scan(&in_a)
	fmt.Print("输入字符串：")
	fmt.Scan(&in_b)
	r := fmt.Sprintf("你输入的数字是：%#v,字符串是%#v", in_a, in_b)
	fmt.Println(r)

	//基本数据类型
	var t1 uint8 = 255
	var tc1 byte = 'a'
	var tc2 rune = '中'
	var t2 float32 = 3.25
	var b1 bool = true
	fmt.Printf("%T: %d\n", t1, t1)
	fmt.Printf("%T: %d %c\n", tc1, tc1, tc1)
	fmt.Printf("%T: %d %c\n", tc2, tc2, tc2)
	fmt.Printf("%T: %f\n", t2, t2)
	fmt.Printf("%T: %#v\n", b1, b1)

	//数组和切片
	var nameList []string = []string{"峰峰知道", "明明", "刚刚"}
	var nameCopy = nameList
	fmt.Println(nameList)
	nameList[1] = "明明1"
	fmt.Println(nameCopy[1]) //引用类型
	fmt.Println(nameList[len(nameList)-1])

	//变长数组就是切片
	nameList = append(nameList, "刚刚append")
	fmt.Println(nameList)

	var slice []int
	fmt.Println(slice == nil, slice) //声明为空
	slice = make([]int, 1, 1)
	fmt.Println(slice == nil, slice)
	fmt.Println("cap:", cap(slice))
	slice = append(slice, 1)
	fmt.Println("cap:", cap(slice))
	slice = append(slice, 2)
	fmt.Println("cap:", cap(slice))
	fmt.Printf("(nameList) %#v,(slice) %#v\n", nameList, slice)
}
